﻿' Cannot database Image's Source directly to URI, must convert 
' http://vivekdalvi.wordpress.com/2008/03/30/binding-to-image-source/
Imports System.Windows.Media.Imaging
Imports System.Windows.Data

Public Class ImageUriConverter
    Implements IValueConverter

    Public Sub New()
    End Sub

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Dim url As String = DirectCast(value, String)
        Dim u As Uri
        If url.Contains(";") OrElse Not url.Contains("/") Then
            u = New Uri(url, UriKind.Relative)
        Else
            u = New Uri(url, UriKind.Absolute)
        End If
        Return New BitmapImage(u)
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class
